package com.draven.mybatis.mapping;

import com.draven.mybatis.transaction.DravenTransactionFactory;
import org.apache.ibatis.transaction.TransactionFactory;

import javax.sql.DataSource;

/**
 * 环境变量对象
 */
public final class DravenEnvironment {
  private final String id;
  private final DravenTransactionFactory transactionFactory;
  private final DataSource dataSource;

  /**
   * 有参构造器 实例化DravenEnvironment
   *
   * @param id
   * @param transactionFactory
   * @param dataSource
   */
  public DravenEnvironment(String id, DravenTransactionFactory transactionFactory, DataSource dataSource) {
    if (id == null) {
      throw new IllegalArgumentException("Parameter 'id' must not be null");
    }
    if (transactionFactory == null) {
      throw new IllegalArgumentException("Parameter 'transactionFactory' must not be null");
    }
    this.id = id;
    if (dataSource == null) {
      throw new IllegalArgumentException("Parameter 'dataSource' must not be null");
    }
    this.transactionFactory = transactionFactory;
    this.dataSource = dataSource;
    System.out.println("=============dataSource 初始化完成============");
    System.out.println("=============DravenEnvironment 初始化完成============");
  }

  public DravenTransactionFactory getTransactionFactory() {
    return this.transactionFactory;
  }

  public DataSource getDataSource() {
    return dataSource;
  }
}
